﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace Phoenix.Xna.Framework
{
    public static class StringHelper
    {
        public static string ObjectToString(object value)
        {
            if (value is Vector2)
            {
                return VectorToString((Vector2)value);
            }
            else if (value is Vector3)
            {
                return VectorToString((Vector3)value);
            }
            else if (value is Vector4)
            {
                return VectorToString((Vector4)value);
            }
            else if (value is Array)
            {
                return ArrayToString((Array)value);
            }
            else
            {
                return value.ToString();
            }
        }

        public static string VectorToString(Vector2 value)
        {
            return string.Format("{0}, {1}", value.X, value.Y);
        }

        public static string VectorToString(Vector3 value)
        {
            return string.Format("{0}, {1}, {2}", value.X, value.Y, value.Z);
        }

        public static string VectorToString(Vector4 value)
        {
            return string.Format("{0}, {1}, {2}, {3}", value.X, value.Y, value.Z, value.W);
        }

        public static string ArrayToString(Array value)
        {
            StringBuilder sb = new StringBuilder();
            List<object> values = new List<object>();

            if (value.GetType() == typeof(bool[]) ||
                value.GetType() == typeof(float[]) ||
                value.GetType() == typeof(int[]) ||
                value.GetType() == typeof(short[]) ||
                value.GetType() == typeof(double[]))
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (i != value.Length - 1)
                    {
                        sb.Append(string.Format("{0},", value.GetValue(i)));
                    }
                    else
                    {
                        sb.Append(value.GetValue(i));
                    }
                }
            }
            else if (value.GetType() == typeof(Vector2[]))
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (i != value.Length - 1)
                    {
                        sb.Append(string.Format("{0}|", VectorToString((Vector2)value.GetValue(i))));
                    }
                    else
                    {
                        sb.Append(VectorToString((Vector2)value.GetValue(i)));
                    }
                }
            }
            else if (value.GetType() == typeof(Vector3[]))
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (i != value.Length - 1)
                    {
                        sb.Append(string.Format("{0}|", VectorToString((Vector3)value.GetValue(i))));
                    }
                    else
                    {
                        sb.Append(VectorToString((Vector3)value.GetValue(i)));
                    }
                }
            }
            else if (value.GetType() == typeof(Vector4[]))
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (i != value.Length - 1)
                    {
                        sb.Append(string.Format("{0}|", VectorToString((Vector4)value.GetValue(i))));
                    }
                    else
                    {
                        sb.Append(VectorToString((Vector4)value.GetValue(i)));
                    }
                }
            }

            return sb.ToString();
        }
    }
}
